//
//  BaoJiaViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/11.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "BaoJiaViewModel.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "BaoJiaBottomButView.h"
#import "BaoJiaGoodsInforTableViewCell.h"
#import "BaoJiaRequirementsTableViewCell.h"
#import "SupplementaryInforTableViewCell.h"
#import "MyMianInforTableViewCell.h"
#import "FootBottomView.h"
#import "BaoJiaDepositTableViewCell.h"

@interface BaoJiaViewModel ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation BaoJiaViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self =[super initWithViewToViewModel:tableView theSuperView:superView]) {
        tableView.height = tableView.height - kHeightProportion_In_iPhoneTriploid(60);
        tableView.mj_footer.hidden = YES;
        tableView.mj_header.hidden = YES;
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        tableView.tableFooterView = [self createFootView];
        [superView addSubview:tableView];
        //
        BaoJiaBottomButView * bottomView = [[BaoJiaBottomButView alloc] initWithFrame:CGRectMake(0, kY_With_View(tableView, 0), KScreenWidth, kHeightProportion_In_iPhoneTriploid(60)) inSuperView:superView];
        
    }
    return self;
}

-(UIView *)createFootView{
    FootBottomView * footView = [[FootBottomView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(60))];
    return footView;
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger cellNum = 1;
    switch (section) {
        case 0:{
            cellNum = 3;
        }
            break;
        case 1:{
            cellNum = 2;
        }
            break;
            
        default:
            break;
    }
    return cellNum;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat cellHeight = 0.01;
    switch (indexPath.section) {
        case 0:{
            if (indexPath.row == 0) {
                cellHeight = kHeightProportion_In_iPhoneTriploid(255);
            }else{
                cellHeight = kHeightProportion_In_iPhoneTriploid(147);
            }
            
        }
            break;
        case 1:{
            if (indexPath.row == 0) {
                cellHeight = kHeightProportion_In_iPhoneTriploid(60);
            }else{
                cellHeight = kHeightProportion_In_iPhoneTriploid(91);
            }
        }
            break;
        case 2:{
            cellHeight = kHeightProportion_In_iPhoneTriploid(120);
        }
            break;
        case 3:{
            cellHeight = kHeightProportion_In_iPhoneTriploid(66);
        }
            break;
            
        default:
            break;
    }
    return cellHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell * cell;
    switch (indexPath.section) {
        case 0:{
            BaoJiaGoodsInforTableViewCell * cell_goods = [BaoJiaGoodsInforTableViewCell cellWithTableView:tableView];
            [cell_goods setSepartionLineWith:lineModel_All];
            cell_goods.Block_PushSelectGoods = ^{
                if (self.delegate && [self.delegate respondsToSelector:@selector(selectStellGoods)]) {
                    [self.delegate selectStellGoods];
                }
            };
            cell = cell_goods;
        }
            break;
        case 1:{
            if (indexPath.row == 0) {
                BaoJiaRequirementsTableViewCell * cell_req = [BaoJiaRequirementsTableViewCell cellWithTableView:tableView];
                cell = cell_req;
            }else{
                SupplementaryInforTableViewCell * cell_supple = [SupplementaryInforTableViewCell cellWithTableView:tableView];
                cell = cell_supple;
            }
        }
            break;
        case 2:{
            MyMianInforTableViewCell * cell_main = [MyMianInforTableViewCell cellWithTableView:tableView];
            cell = cell_main;
        }
            break;
        case 3:{
            BaoJiaDepositTableViewCell * cell_deposit = [BaoJiaDepositTableViewCell cellWithTableView:tableView];
            cell = cell_deposit;
        }
            break;
            
        default:
            break;
    }
    if (cell == nil) {
        cell = [BaseTableViewCell cellWithTableView:tableView];
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return kHeightProportion_In_iPhoneTriploid(10);
    }else{
        return 1.0;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 3) {
        return 1.0;
    }else{
        return 0.01;
    }
}

@end
